package com.mall.ums.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mall.model.domain.ums.Resource;
import com.mall.ums.mapper.ResourceMapper;
import com.mall.ums.service.ResourceService;
import com.mall.utils.PageResult;
import org.springframework.stereotype.Service;

/**
 * @author clutchcitylee
 * @create 2023-03-13-19:47
 */
@Service
public class ResourceServiceImpl extends ServiceImpl<ResourceMapper, Resource> implements ResourceService {
    @Override
    public PageResult list(Integer categoryId, String nameKeyword, String urlKeyword, Integer pageNum, Integer pageSize) {
        Page<Resource> page = new Page<>(pageNum, pageSize);
        LambdaQueryWrapper<Resource> wrapper = new LambdaQueryWrapper<>();
        if (categoryId != null) {
            wrapper.eq(Resource::getCategoryId, categoryId);
        }
        if (nameKeyword != null) {
            wrapper.like(Resource::getName, nameKeyword);
        }
        if (urlKeyword != null) {
            wrapper.like(Resource::getUrl, urlKeyword);
        }
        Page<Resource> resourcePage = this.page(page, wrapper);
        return PageResult.init(resourcePage);
    }
}
